package com.skytech.controller;


import com.alibaba.fastjson.JSONObject;
import com.skytech.service.DeptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@RestController
@RequestMapping("/dept")
public class DeptController {

    @Autowired
    private DeptService deptService;

//    @Autowired
//    private DiscoveryClient client;

    @PostMapping(value = "/addDept")
    public JSONObject addDept(@RequestBody JSONObject params) {
        JSONObject result = new JSONObject();
        boolean flag = deptService.addDept(params);
        result.put("success", true);
        result.put("flag", flag);
        return result;
    }

    @GetMapping(value = "/getAll")
    public JSONObject listAll() {
        JSONObject result = new JSONObject();
        List<JSONObject> Depts = deptService.findAll();
        result.put("success", true);
        result.put("depts", Depts);
        return result;
    }

    @RequestMapping(value = "/findDept", method = RequestMethod.POST)
    public JSONObject findDept(@RequestBody JSONObject params) {
        JSONObject result = new JSONObject();
        JSONObject Dept = deptService.findById(params);
        result.put("success", true);
        result.put("dept", Dept);
        return result;
    }

//    @RequestMapping(value = "/discovery", method = RequestMethod.POST)
//    public Object discovery(){
//        List<String> list = client.getServices();
//
//        System.out.println("**************" + list);
//        List<ServiceInstance> serviceList = client.getInstances("MICROSERVICECLOUD-DEPT");
//
//        for (ServiceInstance instance: serviceList){
//            System.out.println("ServiceId:" + instance.getServiceId() + "\n"
//                    + "Host:" + instance.getHost() + "\n"
//                    + "Port:" + instance.getPort() + "\n"
//                    + "URL:" + "+" + instance.getUri() + "\n");
//        }
//
//        return this.client;
//    }
}
